package com.example.design.beautiful.unit_test.performance_counter.collector;

import com.example.design.beautiful.unit_test.performance_counter.strorage.MetricsStorage;
import org.springframework.util.StringUtils;

/**
 * 负责提供 API，来采集接口请求的原始数据。
 */
public class MetricsCollector {
    //基于接口而非实现编程
    private MetricsStorage metricsStorage;

    public MetricsCollector(MetricsStorage metricsStorage) {
        this.metricsStorage = metricsStorage;
    }

    //用一个函数代替了最小原型中的两个函数
    public void recordRequest(RequestInfo requestInfo) {
        if (requestInfo == null || StringUtils.isEmpty(requestInfo.getApiName())) {
            return;
        }
        metricsStorage.saveRequestInfo(requestInfo);
    }
}
